﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Aga.Psad.Mvc.Models.Home;
using Aga.Psad.Mvc.Helpers;
using Aga.Psad.Backend.Repositories;

namespace Aga.Psad.Mvc.Controllers
{
    [HandleError]
    public class HomeController : ControllerBase
    {
        public ActionResult Index()
        {
            BlogPostRepository blog = new BlogPostRepository();
            var posts = blog.GetPage(0, 3);

            ViewData["BlogPosts"] = posts;

            return View();
        }

        public ActionResult Nosotros()
        {
            ViewData["Menu"] = "nos";

            return View();
        }

        public ActionResult Servicios()
        {
            ViewData["Menu"] = "serv";

            return View();
        }

        public ActionResult Contacto()
        {
            ViewData["Menu"] = "cont";

            return View();
        }

        public ActionResult Filosofia()
        {
            ViewData["Menu"] = "nos";

            return View();
        }

        public ActionResult Localizacion()
        {
            ViewData["Menu"] = "nos";

            return View();
        }

        public ActionResult Equipo()
        {
            ViewData["Menu"] = "nos";

            return View();
        }

        public ActionResult Historia()
        {
            ViewData["Menu"] = "nos";

            return View();
        }

        public ActionResult Clientes()
        {
            ViewData["Menu"] = "cli";

            return View();
        }

        public ActionResult Consulta()
        {
            ViewData["Menu"] = "cont";

            ConsultaViewModel model = new ConsultaViewModel();

            return View(model);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Consulta(FormCollection collection)
        {
            ViewData["Menu"] = "cont";

            ConsultaViewModel model = new ConsultaViewModel();

            UpdateModel(model);

            if (!ModelState.IsValid)
            {
                return View(model);
            }
            else
            {
                EmailHelper.SendContactMail(model.Nombre, model.Apellido, model.Empresa, model.Sector, model.Telefono, model.Email, model.Comentarios);
                return View("ConsultaRecibida");
            }
        }

        public ActionResult CoticeOnline()
        {
            ViewData["Menu"] = "cont";

            CotizacionViewModel model = new CotizacionViewModel();

            return View(model);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CoticeOnline(FormCollection collection)
        {
            ViewData["Menu"] = "cont";

            CotizacionViewModel model = new CotizacionViewModel();

            UpdateModel(model);

            if (!ModelState.IsValid)
            {
                return View(model);
            }
            else
            {
                EmailHelper.SendServiceEstimateMail(
                    model.Nombre, 
                    model.Apellido, 
                    model.Empresa, 
                    model.Sector, 
                    model.Telefono, 
                    model.Email,
                    model.TipoDocumentacion,
                    model.Ubicacion,
                    model.CantidadCajas,
                    model.CantidadConsultas,
                    model.Servicios,
                    model.Comentarios);
                
                return View("CotizacionRecibida");
            }
        }

    }
}
